home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / c++advio 2.3 / Advanced i⁄o / myenv.h < prev    next >
Encoding:
Text File  |  1997-03-05  |  3.2 KB  |  113 lines  |  [TEXT/ALFA]

  1. // This may look like C code, but it is really -*- C++ -*-
  2. // ************************************************************************
  3. //
  4. //            A standard environment
  5. //              I am accustomed to
  6. //
  7. // $Id: myenv.h,v 2.0 1997/03/04 20:29:06 oleg Exp oleg $
  8.  
  9. #ifndef __GNUC__
  10. #pragma once
  11. #endif
  12. #ifndef _myenv_h
  13. #define _myenv_h
  14.  
  15. #ifdef __GNUC__
  16. #pragma interface
  17. #endif
  18.  
  19. #include <stdio.h>
  20.  
  21.  
  22. //------------------------------------------------------------------------
  23. //            Patches to the standard environment
  24.  
  25.  
  26. #if !defined(__GNUC__) && !defined(__MWERKS__)    // If the compiler sucks...
  27. typedef int bool;
  28. #define false 0
  29. #define true (!false)
  30. //enum bool {false,true};
  31. #endif
  32.  
  33.                                 // Like strncpy(), but ALWAYS terminates
  34.                                 // the destination string
  35. char * xstrncpy(char * dest, const char * src, const int len);
  36.  
  37. inline long int sqr(const int x)        { return x*x; }
  38.  
  39.         // Works just as a regular getenv:
  40.         // searches the process' environment for a string of the form
  41.         // name=value and, if the string is
  42.         // present, returns a pointer to the 'value' part of the
  43.         // string.
  44.         // If the string is not present, the default_value is
  45.         // returned, unless it is nil.
  46.         // If the default_value was nil and the string wasn't found,
  47.         // the function prints the message that the name wasn't
  48.         // found, and aborts the program
  49.  
  50. const char * xgetenv(const char * name, const char * default_value);
  51.  
  52.                 // Return TRUE if string s1 starts with s2
  53.                 // i.e., s2 is a prefix of s1
  54.                 // Case doesn't matter
  55. bool does_start_with_ci(const char * s1, const char * s2);
  56.  
  57.  
  58.         // Obtain the size of an existing file
  59.         // If you don't want the function to abort when
  60.         // the file wasn't found/couldn't be accessed,
  61.         // supply your own default action by subclassing from
  62.         // GFS_Default and overriding 'operator ()'
  63. extern struct GFS_Default { virtual size_t operator () (const char * file_name); }
  64.     GFS_default;
  65. size_t get_file_size(const char * file_name,
  66.              GFS_Default& on_error = GFS_default);
  67.  
  68.                 // libg++ nifty timing functions
  69.                 // return_elapsed_time(Last_time) returns
  70.                 // process time (in secs) since Last_Time
  71.                 // If Last_time == 0.0, return time since
  72.                 // the last call to start_timer()
  73. #ifndef __GNUC__
  74. double start_timer(void);
  75. double return_elapsed_time(const double Last_Time);
  76. #endif
  77.  
  78.  
  79. //------------------------------------------------------------------------
  80. //    Assertions, aborts, and related stderr printing
  81.  
  82.                 // Print an error message on stderr and
  83.                 // abort, arguments like those of printf()
  84. void _error(const char * message,...);
  85.  
  86.                 // Print a message on stderr
  87.                 // It looks and acts like printf(), only
  88.                 // prints on stderr (which is unbuffered...)
  89. void message(const char * message,...);
  90.  
  91. #ifndef assert
  92. #define assert(ex) \
  93.         (void)((ex) ? 1 : \
  94.               (_error("Failed assertion " #ex " at line %d of `%s'.\n", \
  95.                __LINE__, __FILE__), 0))
  96. #define assertval(ex) assert(ex)
  97. #endif
  98.  
  99. #define assure(expr,message)                \
  100.     if    (expr) {;}                \
  101.     else _error("%s\n at line %d of '%s'.",message,__LINE__, __FILE__)
  102.  
  103.  
  104.     
  105.                 // Strings of symbols
  106.                 // They may be used as a delimiting lines
  107. extern const char _Minuses [];
  108. extern const char _Asteriscs [];
  109. extern const char _Equals [];
  110.  
  111.  
  112. #endif
  113.